//index.js
//获取应用实例
var app = getApp();
var https = "https://www.moreclub.cn/";
var http2 = 'http://59.110.53.149:8088/'
var value = '一个人喝酒超级无聊，想找好玩朋友拼个座，带我飞。';
var v;
var leg;
var city;
var txt = 0;
var type = 5;
var mid;
var midtxt;
var gift;
Page({

  data: {
    winWidth: 0,
    winHeight: 0,
    // tab切换 
    currentTab: 0,
    animationData: {},
    value:'一个人喝酒超级无聊，想找好玩朋友拼个座，带我飞。'
  },

  onShow: function(){
    var that = this
    var nametxt = app.globalData.nametxt
    midtxt = app.globalData.midtxt 
    that.setData({
      nametxt:nametxt,
      midtxt:midtxt
    })

    var animation = wx.createAnimation({
      duration: 500,
      timingFunction: 'linear',
    })

    this.animation = animation

    setTimeout(function () {
      animation.translate(270).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 500)

  },
  
  onLoad: function (options) {
    var that = this;
    
    try {
      wx.setStorageSync('mid',options.mid)
    } catch (e) {
    }
    that.setData({
      mid:options.mid
    })

    //位置
    city = wx.getStorageSync('city');
    var lat1 = wx.getStorageSync('lat1');
    var lng1 = wx.getStorageSync('lng1');
    if (city == '' || !city || typeof (city) == "undefined") {
      city = 'cd'
    }
    if (lat1 == '' || !lat1 || typeof (lat1) == "undefined") {
      lat1 = '30.632938'
    }
    if (lng1 == '' || !lng1 || typeof (lng1) == "undefined") {
      lng1 = '104.054685'
    }
  
    wx.request({
      url: https + 'v1/merchant/open/nearby/' + city,
      // dataType: "json",
      data: {
        pn: 0,
        ps: 5,
        //location: '104.054685,30.632938'
        location: lng1 + ',' + lat1
      },
      success: function (res) {
        console.log(res)

        var resData = res.data.data

        that.setData({
          resData: resData
        })
      }
    }) 
    
  },
  onUnload: function () {
    try {
      wx.removeStorageSync('idn')
    } catch (e) {
    }
  },

  swich_local: function () {
    wx.navigateTo({
      url: '../location/location?all=1'
    })
  },
  /** 
   * 点击tab切换 
   */
  num: function (e) {
    var that = this;
    var n = e.detail.value.length;
    v = e.detail.value; 
    try {
      wx.setStorageSync('v', v);
    } catch (e) {
    }
    that.setData({
      n: n
    })
  },
  bur:function(e){
      v = e.detail.value; 
      try {
        wx.setStorageSync('v', v);
      } catch (e) {
      }
  },

  swichNav: function (e) {

    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
    if (e.target.dataset.current == 0) {
      txt = 0;
      type = 5;
      value = '一个人喝酒超级无聊，想找好玩朋友拼个座，带我飞。'
      that.setData({
        value: value,

      })
    }
    if (e.target.dataset.current == 1) {
      txt = 1;
      type = 3;
      value = '聊音乐，电影，酒...认识有趣的你！'
      that.setData({
        value: value
      })
    }
    if (e.target.dataset.current == 2) {
      txt = 2;
      type = 6;
      value = '急！玩游戏缺人，求旁边的帅哥靓女加入~'
      that.setData({
        value: value
      })
    }
    if (e.target.dataset.current == 3) {
      txt = 3;
      type = 4;
      value =  '城市小白，求土著支招好吃的好玩的去处！'
      that.setData({
        value: value
      })
    }
    if (e.target.dataset.current == 4) {
      txt = 4;
      type = 1;
      value = '遇见生活小难题，求大神支招！'
      that.setData({
        value: value
      })
    }
    if (e.target.dataset.current == 5) {
      txt = 5;
      type = 2;
      value = '开车堵，上班老板不酷，回家生活不酷，憋着难受，这里说点酷的！'
      that.setData({
        value: value
      })
    }

  },

  swich: function (e) { 
    var that = this;
    console.log(that.data)
    if (this.data.current === e.target.dataset.curren) {
      // return false;
      leg = -1
      that.setData({
        current: -1
      })
    } else {
    
      if(e.target.dataset.curren==0){
        leg = 0
        gift = 1
      }
      if (e.target.dataset.curren == 1) {
        leg = 1
        gift = 2
      }
      if (e.target.dataset.curren == 2) {
        leg = 2
        gift = 3
      }
      if (e.target.dataset.curren == 3) {
        leg = 3
        gift = 4
      }
      if (e.target.dataset.curren == 4) {
        leg = 4
        gift = 5
      }
      if (e.target.dataset.curren == 5) {
        leg = 5
        gift = 6
      }
      if (e.target.dataset.curren == 6) {
        leg = 6
        gift = 7
      }
      if (e.target.dataset.curren == 7) {
        leg = 7
        gift = 8
      }
      if (e.target.dataset.curren == 8) {
        leg = 8
        gift = 9
      }
      that.setData({
        current: e.target.dataset.curren
      })
    }
  },


  skip:function(e){
    var exprise;
    var that = this;
    var pages = getCurrentPages();

    var currPage = pages[pages.length - 1];   //当前页面
    var prevPage = pages[pages.length - 2];  //上一个页面
    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    var access_token = wx.getStorageSync('inToken');
    var uid = wx.getStorageSync('uid');
    var v = wx.getStorageSync('v');
    if(mid){
      mid = wx.getStorageSync('mid');
    }else{
      mid = midtxt
    }
    
    console.log(v)
    if(v){
      v = v
      
    }else{
      v = value;
     
    }
   

    wx.request({
      url: https + 'v2/signinter/add?mid='+mid + "&uid=" + uid + '&access_token=' + access_token,
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      data: {
        'mid': mid,
        'gift': gift,
        'type': type,
        'uid': uid,
        'content': v,
        'access_token': access_token

      },
      success: function (res) {
        console.log(res)
        var personData = res.data.data;
       

      // wx.showToast({
      //   title: '发布成功',
      //   // icon: 'success',
      //   duration: 2000
      // })

     
    }
  })


    prevPage.setData({
      //mydata: { a: txt, b: 2 }
      mydata:{
        txt:txt,
        v:v,
        leg:leg,
        isShowToast:true
      }
      // didian: e.currentTarget.dataset.city
      
    })
    if (pages[1].route =='pages/interaction/interaction'){
      wx.redirectTo({
        url: '../citysetlist/citysetlist'
      })
    }else{
      wx.navigateBack({
        delta: 1,

      })
      var that = this;
      that.setData({
        isOpacity: false
      })
    }
     
      
      // var pages = getCurrentPages();
      // var prevPage = pages[pages.length - 2];
      // prevPage.setData({
      //   mydata: { a: 1, b: 2 }
      // })
  },

   onShareAppMessage: function () {
    // 用户点击右上角分享
    var mid = wx.getStorageSync('mid');
    return {
      title: '玩互动-发拼座', // 分享标题
      desc: '玩互动', // 分享描述
      path: '/pages/interaction/interaction?mid=' + mid  // 分享路径
    }
  },

  
})